#include "Main.h"
#include "Demo1.h"
#include "Demo.h"
#include "cm.h"
#include "dp.h"
#include "Sensor.h"

extern int z;
int sensor_data = 0;
int i = 0;
int j = 0;

void test_Sensor();
void test_Com_Dp();

int main(int argc,char *argv[]){
    int choice;
    while (1) {
        printf("\nMain Operations:\n");
        printf("1. test_Sensor\n");
        printf("2. test_Com_Dp\n");
        printf("9. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                test_Sensor();
                break;
            case 2:
                test_Com();
                break;
            case 9:
                printf("Exiting...\n");
                return 0;
            default:
                printf("Invalid choice. Please try again.\n");
        }
    }

    return 0;
}

void test_Sensor(){
    pthread_t pid;
    
    pthread_create(&pid, NULL, sens, NULL);

    //Maintain the acquisition of sensor data.

    for(;;){
        printf("sensor_data = %d\n",sensor_data);
        sleep(1);
    }

    pthread_join(pid, NULL);

    return;
}

void test_Com_Dp(){
    pthread_t pid;
    int a = 30;

    // communication module receives messages
    pthread_create(&pid, NULL, rec, (void *)&a);

    pthread_join(pid, NULL);

    return;
}